package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.consts.ErmsCodePrefix;
import com.sugon.dao.SpecialDevForkTruckDao;
import com.sugon.entity.SpecialDevForkTruckEntity;
import com.sugon.service.SpecialDevForkTruckService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 特种设备-叉车台账Service实现类
 *
 * @author sugon
 * @date 2021-09-08 16:30:39
 */
@Service("specialDevForkTruckService")
public class SpecialDevForkTruckServiceImpl implements SpecialDevForkTruckService {
    @Autowired
    private SpecialDevForkTruckDao specialDevForkTruckDao;

    @Override
    public SpecialDevForkTruckEntity queryObject(String id) {
        return specialDevForkTruckDao.queryObject(id);
    }

    @Override
    public List<SpecialDevForkTruckEntity> queryList(Map<String, Object> map) {
        return specialDevForkTruckDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return specialDevForkTruckDao.queryTotal(map);
    }

    @Override
    public String generateUniqueCode() {
        String lastestEquipmentCode = specialDevForkTruckDao.getLastestEquipmentCode(ErmsCodePrefix.FORK_TRUCK_CODE_PREFIX);
        return com.sugon.modules.utils.StrUtil.increase(lastestEquipmentCode, ErmsCodePrefix.FORK_TRUCK_CODE_PREFIX, 5, 1);
    }

    @Override
    public int save(SpecialDevForkTruckEntity specialDevForkTruck) {
        specialDevForkTruck.setId(RandomUtil.randomString(32));
        specialDevForkTruck.setGmtCreate(DateUtil.date());
        specialDevForkTruck.setCreateUser(ShiroUtils.getUserId());
        specialDevForkTruck.setEquipmentCode(generateUniqueCode());
        return specialDevForkTruckDao.save(specialDevForkTruck);
    }

    @Override
    public int update(SpecialDevForkTruckEntity specialDevForkTruck) {
        specialDevForkTruck.setGmtModified(DateUtil.date());
        specialDevForkTruck.setUpdateUser(ShiroUtils.getUserId());
        return specialDevForkTruckDao.update(specialDevForkTruck);
    }

    @Override
    public int delete(String id) {
        return specialDevForkTruckDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return specialDevForkTruckDao.deleteBatch(ids);
    }
}
